package cn.zhc.com.base;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.gyf.barlibrary.ImmersionBar;

import cn.zhc.com.R;
import cn.zhc.com.event.EventInfo;
import cn.zhc.com.utils.UtilsOther;
import cn.zhc.com.utils.UtilsToast;
import cn.zhc.com.utils.UtilsUI;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by zhouhongchun on 2017/8/14.
 */

public abstract class BaseActivity extends AppCompatActivity {

    private Unbinder mUnbinder;
    private Unbinder mUnbinder2;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        UtilsOther.showActivityInAnim(this);
        initWindow();
        setContentView(bindLayout());
        mUnbinder = ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        init();
    }



    protected abstract void onEventBusMainThread(EventInfo mEventInfo);
    @Subscribe(threadMode = ThreadMode.MAIN) //在ui线程执行
    public void onEventMainThread(EventInfo mEventInfo) {
        onEventBusMainThread(mEventInfo);

    }

    /**
     * 填充布局文件
     * @return
     */
    protected abstract int bindLayout();

    /**
     * 初始化
     */
    protected abstract void init();

    private ImmersionBar mImmersionBar;
    /**
     * 初始化状态栏
     */
    public void initWindow() {
//        mImmersionBar = ImmersionBar.with(this);
//        mImmersionBar.init();

        UtilsUI.initStateStatusColor(this,2);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mUnbinder.unbind();
        EventBus.getDefault().unregister(this);
        UtilsToast.hideToast();
        if (mImmersionBar != null){
            ImmersionBar.with(this).destroy();
        }

    }
    @Override
    public void finish() {
        super.finish();
        UtilsOther.showActivityExitAnim(this);
    }



}
